﻿<UserControl x:Class="RequestsGrid" Name="rg1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ProgettoSicurezza.CertificationAuthority"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">
    <UserControl.Resources>
        <local:RequestStatusToBooleanConverter x:Key="r2b"/>

        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Status}" Value="Pending">
                    <Setter Property="Background" Value="LightYellow" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Accepted">
                    <Setter Property="Background" Value="PaleTurquoise" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Fulfilled">
                    <Setter Property="Background" Value="PaleGreen" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Refused">
                    <Setter Property="Background" Value="Tomato" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Renewed">
                    <Setter Property="Background" Value="GreenYellow" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <DataGrid Name="dg" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" VerticalScrollBarVisibility="Auto">
            <DataGrid.Columns>

                <DataGridTemplateColumn Header="Time of request" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding RequestDateTime}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="User Name" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding UserName}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Request Type" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding RequestType}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Status" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Status}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>



                <DataGridTemplateColumn Header="Action" IsReadOnly="True" Width="*">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" IsEnabled="{Binding Status, Converter={StaticResource r2b}, Mode=OneWay}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2">
                                <Button Content="Confirm" Margin="2" Click="ButtonConfirm_Click" Width="100"/>
                                <Button Content="Reject" Margin="2" Click="ButtonReject_Click" Width="100"/>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>


        <GroupBox Header="Filter" Grid.Row="1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="Only show requests that are:" Margin="3" HorizontalAlignment="Center"/>
                <Label Background="LightYellow" Grid.Column="1" HorizontalContentAlignment="Center">
                    <CheckBox Content="Pending" ToolTip="Requests waiting to be confirmed or rejected by the CA administrator" Click="FilterChanged" Name="cbPending" IsChecked="True" IsThreeState="False"/>
                </Label>
                <Label Background="PaleTurquoise" Grid.Column="2" HorizontalContentAlignment="Center">
                    <CheckBox Content="Accepted" ToolTip="Requests that have been accepted, but the client hasn't downloaded the certificate yet" Click="FilterChanged" Name="cbAccepted" IsChecked="True" IsThreeState="False"/>
                </Label>
                <Label Background="PaleGreen" Grid.Column="3" HorizontalContentAlignment="Center">
                    <CheckBox Content="Fulfilled" ToolTip="Certificate generated and downloaded by the client" Click="FilterChanged" Name="cbFulfilled" IsChecked="True" IsThreeState="False"/>
                </Label>
                <Label Background="GreenYellow" Grid.Column="4" HorizontalContentAlignment="Center">
                    <CheckBox Content="Renewed" ToolTip="Requests corresponding to renewal of certificates" Click="FilterChanged" Name="cbRenewed" IsChecked="True" IsThreeState="False"/>
                </Label>
                <Label Background="Tomato" Grid.Column="5" HorizontalContentAlignment="Center">
                    <CheckBox Content="Rejected" ToolTip="Requests that have been rejected by the CA administrator" Click="FilterChanged" Name="cbRejected" IsChecked="True" IsThreeState="False"/>
                </Label>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
